<template>
	<view class="mainpadding2">
		<u-navbar title="購買須知範例" placeholder autoBack>
			<view class="flexright xiaohui" slot="right" @click="jumpurl('/pages/workbench/tianjiagmfl')">添加</view>
		</u-navbar>
		<view class="flexcenter" v-if="!list.data.length">
			<view class="placeholderimage" style="margin-top: 100rpx;" ></view>
		</view>
		<view class="mainpadding_top ffffff " v-for="item in list.data" :key="item.id" @click="checkitem(item.des)">
			<view class="xiahuax">
				<view class="titletext xiaohuang bold">{{item.name}}</view>
				<view class="ershib xiaohui margin-top xiankuan1">{{item.des}}</view>
			</view>
			<view class="flexright margin-top" @click.stop="jumpdetail('/pages/workbench/tianjiagmfl?id=',item.id)">
				<view class="flexleft margin_left">
					<u-icon name="edit-pen" color="#999" size="16"></u-icon>
					<view class="xiaohei">編輯</view>
				</view>
				<view class="flexleft margin_left" @click.stop="delitem(item.id)">
					<u-icon name="trash" color="#999" size="16"></u-icon>
					<view class="xiaohei">刪除</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				type:0
			}
		},
		onLoad(options) {
			if(options.type){
				this.type = options.type
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			checkitem(des){
				if(this.type==1){
					uni.$emit("checkgmzx",des)
					uni.navigateBack(1)
				}
			},
			delitem(id) {
				this.http.modal('提示', '確認刪除當前數據嗎？', true, (res) => {
					if (res) {
						this.http.request("/api/goods/delGoodsXz", 'GET', {
							id
						}).then(res=>{
							if (res.code == 1) {
								this.http.toast("刪除成功")
								this.init()
							} else{
								this.http.toast(res.msg);
							}
						})
						
					}
				})
			},
			init(isPage, page) {
				let _this = this
				httpRequest.request('/api/goods/goodsXzIndex', 'GET', {
					page: page || 1,
					limit: 12,
					shop_id:uni.getStorageSync("shop_id"),
					type:2
				}).then(res => {
					uni.stopPullDownRefresh()
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
		}
	}
</script>

<style>
.xiahuax {
		padding-bottom: 30rpx;
		border-bottom: 2rpx solid rgba(0, 0, 0, 0.03);
	}
	.xiankuan1 {
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden; //溢出内容隐藏
		text-overflow: ellipsis; //文本溢出部分用省略号表示
		display: -webkit-box; //特别显示模式
		-webkit-line-clamp: 2; //行数
		line-clamp: 2;
		-webkit-box-orient: vertical; //盒子中内容竖直排列
	}
</style>
